﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Entity;
using Utility;

namespace DAL
{
    public class RecordDAO
    {
        public static int GetReservedNum(int serviceId, string day, string timeBucket)
        {
            string sql = SqlSentence.getReservedNum;
            SqlParameter[] parameter =
            {
                new SqlParameter("@ServiceId", serviceId),
                new SqlParameter("@Day", day),
                new SqlParameter("@TimeBucket", timeBucket)                
            };
            return SqlHelper.GetCountResult(sql, parameter);
        }

        public static int InsertRecord(AppointmentRecord record)
        {
            string sql = SqlSentence.insertRecord;
            SqlParameter[] parameter =
            {
                new SqlParameter("@ServiceId", record.ServiceId),
                new SqlParameter("@ApplicantId", record.ApplicantId),
                new SqlParameter("@Day", record.Day),
                new SqlParameter("@TimeBucket", record.TimeBucket),
                new SqlParameter("@Status", record.Status)
            };
            return SqlHelper.ExecteTextGetIdentity(sql, parameter);
        }

        public static DataTable GetRecordsTable(int user, string loginType)
        {
            string sql = string.Empty;
            if ("Student" == loginType)
            {
                sql = SqlSentence.getRecordsForStudent;
            }
            else if ("Director" == loginType)
            {
                sql = SqlSentence.getRecordsForDirector;
            }

            SqlParameter[] parameter =
            {
                new SqlParameter("@user", user)              
            };
            return SqlHelper.GetSingleTableText(sql, parameter);
        }

        public static DataTable GetRecordCommonTable(int appointmentId)
        {
            string sql = SqlSentence.getRecordCommonTable;
            SqlParameter[] parameter =
            {
                new SqlParameter("@AppointmentId", appointmentId)              
            };
            return SqlHelper.GetSingleTableText(sql, parameter);
        }

        public static int UpdateRecordStatusByDirector(int recordId, string status, string approvalComment)
        {
            string sql = SqlSentence.updateRecordStatusByDirector;
            SqlParameter[] parameter =
            {
                new SqlParameter("@AppointmentId", recordId),
                new SqlParameter("@Status", status),
                new SqlParameter("@ApprovalComment", approvalComment)
                
            };
            return SqlHelper.ExecteNonQueryText(sql, parameter);
        }

        public static int StudentMakeComment(int recordId, string comment)
        {
            string sql = SqlSentence.studentMakeComment;
            SqlParameter[] parameter =
            {
                new SqlParameter("@AppointmentId", recordId),
                new SqlParameter("@Comment", comment)
                
            };
            return SqlHelper.ExecteNonQueryText(sql, parameter);
        }
    }    
}
